package com;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Test1_1 {
    public static void main(String[] args) throws Exception {
        //
        Class.forName("com.mysql.jdbc.Driver");
        //注册驱动包
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db2", "root", "root");
      //获取数据库连接对象
        String sql = "insert  into  emp(id,name)  values(null,'诸葛亮')";
        //定义一条sql语句
        Statement stmt = conn.createStatement();//获取sql语句执行对象
        int i = stmt.executeUpdate(sql);//
        System.out.println(i);//
        stmt.close();//释放资源
        conn.close();//释放资源
    }

}
